<%@page import="org.jeecgframework.web.util.StaticValue"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>创建</title>
	<script type="text/javascript" src="plug-in/mutiLang/zh-cn.js"></script>
	<script type="text/javascript" src="plug-in/jquery/jquery-1.8.3.js"></script>
	<script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
	<%--<script type="text/javascript" src="plug-in/"></script>--%>
	<script type="text/javascript" src="plug-in/tools/dataformat.js"></script>
	<link id="easyuiTheme" rel="stylesheet" href="plug-in/easyui/themes/default/easyui.css" type="text/css"></link>
	<link rel="stylesheet" href="plug-in/easyui/themes/icon.css" type="text/css"></link>
	<link rel="stylesheet" type="text/css" href="plug-in/accordion/css/accordion.css">
	<script type="text/javascript" src="plug-in/easyui/jquery.easyui.min.1.3.2.js"></script>
	<script type="text/javascript" src="plug-in/easyui/locale/zh-cn.js"></script>
	<script type="text/javascript" src="plug-in/tools/syUtil.js"></script>
	<script type="text/javascript" src="plug-in/easyui/extends/datagrid-scrollview.js"></script>
	<script type="text/javascript" src="plug-in/My97DatePicker/WdatePicker.js"></script>
	<link rel="stylesheet" href="plug-in/tools/css/common.css" type="text/css"></link>
	<script type="text/javascript" src="plug-in/lhgDialog/lhgdialog.min.js"></script>
	<script type="text/javascript" src="plug-in/tools/curdtools_zh-cn.js"></script>
	<script type="text/javascript" src="plug-in/tools/easyuiextend.js"></script>
	<script type="text/javascript" src="plug-in/jquery-plugs/hftable/jquery-hftable.js"></script>
	<link rel="stylesheet" href="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.css" type="text/css"></link>
	<script type="text/javascript" src="plug-in/jquery/jquery-autocomplete/jquery.autocomplete.min.js"></script>
	<link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css" />
	<script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>
</head>

<body>
<t:formvalid layout="" dialog="false" formid="formobj" >
	<div style="margin-bottom:10px;">
		<img style="margin-bottom:-7px" src="plug-in/login/images/dispatch bill.png">
		<span class="list-title"></span>
		<div style="position: absolute; text-align: center; width: 100%; margin-top:-20px;">
			<a href="#" class="easyui-linkbutton l-btn" onclick="submit()">提交</a>
		</div>
	</div>

	<div class="subtitle">
		<p>合同基本信息</p>
		<table class="nobordertable noborder">
			<tbody>
			<tr>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>合同名称:</label>
				</td>
				<td width="30%">
					<input id="contractName" name="contractName" datatype="*" type="text" style="width: 300px" class="inputxt">
					<span class="Validform_checktip"></span>
					<label class="Validform_label" style="display: none;">合同名称</label>
				</td>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>甲方名称:</label>
				</td>
				<td width="30%">
					<input id="clientName" name="clientName" datatype="*" type="text" style="width: 300px" class="inputxt">
					<span class="Validform_checktip"></span>
					<label class="Validform_label" style="display: none;">甲方名称</label>
				</td>
			</tr>
			<tr>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>合同编号:</label>
				</td>
				<td width="30%">
					<input id="contractCode" name="contractCode" type="text" style="width: 300px"
						   class="inputxt" datatype="*" ajaxurl="cbsContractController.do?checkInfo">
					<span class="Validform_checktip"></span>
					<label class="Validform_label" style="display: none;">合同编号</label>
				</td>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>合同类型:</label>
				</td>
				<td width="30%">
						<%--<t:dictSelect field="contractType" id="contractType" defaultVal='${cbsContractPage.contractType}' type="select" typeGroupCode="<%=StaticValue.CBS_CONTRACT_TYPE %>"  />--%>
					<select name="contractType" id="contractType">
						<option value="1">维保合同</option>
						<option value="2">销售合同</option>
						<option value="3">模板合同</option>
						<option value="4">其他</option>
					</select>
				</td>
			</tr>
			<tr>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>合同生效日期:</label>
				</td>
				<td width="30%">
						<%--<input class="Wdate"  onClick="WdatePicker()"/>--%>
					<input class="Wdate" id="contractDate" name="contractDate" datatype="*" type="text" onClick="WdatePicker()" style="width: 150px" class="inputxt"
						   value="<fmt:formatDate  value="${cbsContractPage.contractDate }" type="both" pattern="yyyy-MM-dd" />" >
					<span class="Validform_checktip"></span>
					<label class="Validform_label" style="display: none;">合同生效日期</label>
				</td>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>合同签署人:</label>
				</td>
				<td width="30%">
					<input id="contractSignUser" name="contractSignUser" datatype="*" type="text" style="width: 150px" class="inputxt">
					<span class="Validform_checktip"></span>
					<label class="Validform_label" style="display: none;">合同签署人</label>
				</td>
			</tr>
			<tr>
				<td class="al_r" valign="top">备注:</td>
				<td colspan="3">
					<textarea style="width: 90%; height: 60px;" class="inputxt" id="memo" name="memo"></textarea>
				</td>
			</tr>
			</tbody>
		</table>
	</div>

	<div class="subtitle">
		<p>SLA</p>
		<div style="width: 98%; margin: 5px auto;">
			<a href="#" class="easyui-linkbutton l-btn" onclick="selectContractTemplate();">选择合同模板</a>
				<%--<td class="value" style="width: 500px;">
                    <input name="" id="slcontractCode" type="hidden">
                    <input name="slcontractName" id="contractName" class="inputxt" readonly="readonly" datatype="*" style="width:260px;"/>
                    &lt;%&ndash;fun="cinemaChooseBack"&ndash;%&gt;
                    <t:choose hiddenName="contractCode" hiddenid="id" url="cbsContractController.do?selectContractTemplate" name="cbsContractList" height="500px" width="500px"
                              icon="icon-search" title="选择合同模板" textname="contractName" isclear="true"></t:choose>
                </td>--%>

		</div>
		<table class="ftable">
			<tbody>
			<tr>
				<th>服务条款</th>
				<th>是否包含</th>
				<th>选项</th>
				<th>标准项目</th>
				<th>增减项/说明</th>
			</tr>
			<c:forEach items="${slaList}" var="sla" varStatus="a">
				<tr>
					<td>
						<input type="hidden" name="id" value="${sla.id}">
						<input type="hidden" name="serviceName" value="${sla.serviceName}">
							${sla.serviceName}
					</td>
					<td>
						<input type="checkbox" name="contain" id="${sla.id}" value="${sla.contain}"} />
					</td>
					<td>
							<%--<t:dictSelect field="serviceItem" defaultVal='${sla.serviceItem}' type="select" typeGroupCode="<%=StaticValue.DIC_TRUE_OR_FALSE_NUM %>"  />--%>
							<%--<input id="serviceItem" name="serviceItem" type="hidden" style="width: 150px" class="inputxt" value='${sla.serviceItem}'>--%>
						<select style="width:auto;" id="serviceItem" name="serviceItem">
							<c:forEach items="${sla.serviceItems }" var="a">
								<option value="${a}" <c:forEach items="${sItemList}" var="b"><c:if test="${sla.id==b.slaId.id}"><c:if test="${b.sItem==a}">selected="selected"</c:if></c:if></c:forEach> >${a}</option>
							</c:forEach>
						</select>
					</td>
					<td>
						<input type="hidden" name="description" value="${sla.description}">
							${sla.description}
					</td>
					<td>
						<textarea style="width: 90%;" name="supplement"></textarea>
					</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
		<table class="nobordertable noborder">
			<tbody>
			<tr>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>维修派单规则:</label>
				</td>
				<td width="30%">
					<select style="width:auto;" name="repairProvider" id="repairProvider" datatype="*">
						<c:forEach items="${tsDeparts }" var="depart">
							<option value="${depart.orgCode }" <c:if test="${depart.orgCode eq '77'}"> selected="selected"</c:if> >${depart.shortname }</option>
						</c:forEach>
					</select>
					<select style="width:auto;" name="repairType" id="repairType">
						<option value="1">推荐</option>
						<option value="2">指定</option>
					</select>
				</td>
				<td class="al_r" width="20%">
					<span style="color:red;">*</span><label>巡检派单规则:</label>
				</td>
				<td width="30%">
					<select style="width:auto;" name="inspectionProvider" id="inspectionProvider" datatype="*">
						<c:forEach items="${tsDeparts }" var="depart">
							<option value="${depart.orgCode }" <c:if test="${depart.orgCode eq '77'}"> selected="selected"</c:if> >${depart.shortname }</option>
						</c:forEach>
					</select>
					<select style="width:auto;" name="inspectionType" id="inspectionType">
						<option value="1">推荐</option>
						<option value="2">指定</option>
					</select>
				</td>
			</tr>
			<tr>
				<td class="al_r" valign="top"><label>特别服务承诺:</label></td>
				<td colspan="3">
					<textarea style="width: 90%; height: 60px;" name="serviceCommitment" id="serviceCommitment"></textarea>
				</td>
			</tr>
			<tbody/>
		</table>
	</div>
</t:formvalid>
</body>

</html>

<script type="text/javascript">
    //选择SLA后回显复选框
    var code="${code}";
    var arry=new Array();
    <c:forEach items="${slaId }" var="sla">
    arry.push("${sla}");
    </c:forEach>
    if(code=='choose'){
        for(var i=0;i<arry.length;i++){
            $("[name='contain']").each(function (){
                if($(this).attr("ID")==arry[i]){
                    $(this).attr("checked",true);
                }
            })
        }
        var contractCode = $.session.get('contractCode');
        var contractType = $.session.get('contractType');
        var contractName = $.session.get('contractName');
        var clientName = $.session.get('clientName');
        var contractDate = $.session.get('contractDate');
        var contractSignUser = $.session.get('contractSignUser');
        var memo = $.session.get('memo');
        $("#contractCode").val(contractCode);
        $("#contractType").val(contractType);
        $("#contractName").val(contractName);
        $("#clientName").val(clientName);
        $("#contractDate").val(contractDate);
        $("#contractSignUser").val(contractSignUser);
        $("#memo").val(memo);
        $.session.clear();
    }else{
        $("[name='contain']").each(function (){
            if($(this).val()==1){
                $(this).attr("checked",true);
            }
        })
    }
    var form=$("#formobj").Validform({
        ignoreHidden:true,
        postonce:true,
        showAllError : true,
        ajaxPost:true,
        tiptype:3,
    })
    function submit() {
        //调用formValidata 进行验证，并能阻止提交
        if(!form.check(true)){
            form.submitForm(false);
            return false;
        }
        $("[name='contain']").each(function (){
            if($(this).prop('checked')==true){
                $(this).val(1);
            }else{
                $(this).val(2);
            }
        });
        var obj = new Object();
        obj.contractCode = $("#contractCode").val();
        obj.contractType = $("#contractType").val();
        obj.contractName = $("#contractName").val();
        obj.clientName = $("#clientName").val();
        obj.contractDate = $("#contractDate").val();
        obj.contractSignUser = $("#contractSignUser").val();
        obj.memo = $("#memo").val();
        obj.repairProvider = $("#repairProvider").val();
        obj.repairType = $("#repairType").val();
        obj.inspectionProvider = $("#inspectionProvider").val();
        obj.inspectionType = $("#inspectionType").val();
        obj.serviceItem = $("#serviceItem").val();
        obj.serviceCommitment = $("#serviceCommitment").val();
        var serviceItems=[];
        var a=0;
        $("[name='serviceItem']").each(function (){
            serviceItems[a]=$(this).val();
            a++;
        });
        var ids=[];
        var m=0;
        $("[name='id']").each(function (){
            ids[m]=$(this).val();
            m++;
        });
        var contain=[];
        var s=0;
        $("[name='contain']").each(function (){
            contain[s]=$(this).val();
            s++;
        });
        var supplement=[];
        var u=0;
        $("[name='supplement']").each(function (){
            supplement[u]=$(this).val();
            u++;
        });
        var serviceName=[];
        var b=0;
        $("[name='serviceName']").each(function (){
            serviceName[b]=$(this).val();
            b++;
        });
        var description=[];
        var c=0;
        $("[name='description']").each(function (){
            description[c]=$(this).val();
            c++;
        });
        obj.serviceItems = serviceItems;
        obj.serviceName = serviceName;
        obj.description = description;
        obj.ids = ids;
        obj.contain = contain;
        obj.supplement = supplement;
        console.log(JSON.stringify(obj));
        //保存
        $.ajax({
            async : false,
            cache : false,
            type : 'POST',
            data : obj,
            traditional:true,
            url : 'cbsContractController.do?doAdd', // 请求的action路径
            error : function() {// 请求失败处理函数
            },
            success : function(data) {
                var d = $.parseJSON(data);
                console.log(d);
                if (d.success) {
                    addOneTab('合同管理', 'cbsContractController.do?cbsContract&code=add', '');
                    closetab("新建合同");
                }else{
                    tip("当前合同编号已存在");
                }
            }
        });
    }

    //选择合同模板
    function selectContractTemplate(){
        var contractCode=$("#contractCode").val();
        var contractType = $("#contractType").val();
        var contractName = $("#contractName").val();
        var clientName = $("#clientName").val();
        var contractDate = $("#contractDate").val();
        var contractSignUser = $("#contractSignUser").val();
        var memo = $("#memo").val();
        $.session.set('contractCode',contractCode)
        $.session.set('contractType', contractType)
        $.session.set('contractName', contractName)
        $.session.set('clientName', clientName)
        $.session.set('contractDate', contractDate)
        $.session.set('contractSignUser', contractSignUser)
        $.session.set('memo', memo)
        openwindow('选择合同模板','cbsContractController.do?selectContractTemplate','',500, 300);
    }
</script>